<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">属性确认</h3></div>
            <div class="panel-body">
                <div class="container-fluid">
                    <div class="col-sm-12 col-md-3  add-space">
                        <div class="input-group input-group-md">
                            <span class="input-group-addon">扫货收货明细单号</span>
                            <input class="form-control" type="text" name="recieve_details_id"
                                   onkeyup="this.value=this.value.replace(/\D/g,'')">
                        </div>
                    </div>

                    <div class="col-md-2 add-space">
                        <input class="btn btn-primary" type="button" onclick="getInfo()" value="查询">
                        <!--<input class="btn btn-primary" type="button" value="下载">-->
                    </div>

                </div>
                <div class="clearfix"></div>
                <hr>
                <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th>站点</th>
                        <th>供应商名称</th>
                        <th>采购单号</th>
                        <th>收货明细单号</th>
                        <th>SKU</th>
                        <th>采购名称</th>
                        <th>所属仓库</th>
                        <th>备注</th>
                        <th>审核人员</th>
                        <th>审核时间</th>
                        <th>请选择属性</th>
                        <th>到货数量</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr id="txtHint"></tr>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
    /**
     * 根据收货明细单号获取详情
     */
    function getInfo() {
        var recieveDetailsId = $("input[name='recieve_details_id']").val();
        if ('' == recieveDetailsId) {
            layer.msg('请输入收货明细单号',{'icon':'5'});
            return;
        }

        $.ajax({
            url: "__URL__/attr_confirm_index",
            data: {'recieveDetailsId': recieveDetailsId},
            type: 'get',
            dataType: 'json',
            async: true,

            success: function (data) {
                var obj = (new Function('return ' + data + ';'))();
                var strTem = '';
                var button = '';

                if(undefined == obj.id){
                    layer.msg('该明细单不存在!',{'icon':'5'});
                    return;
                }
                if (obj.logisticsCheck!=20){
                    button = '<button type="button" class="btn btn-info btn-sm" id="check" onclick="checkSkuLogistic()">审核</button>';
                }  else {
                    button = '<button type="button" class="btn btn-access btn-sm">已审核</button>';
                }

                if (null == obj.check_man) {
                    obj.check_man = '';
                    obj.att_time = '';
                }

                strTem += '<td>' + obj.site_id + '</td>' +
                        '<td>' + obj.supplier + '</td>' +
                        '<td id="poId">' + obj.purchaseorder_id + '</td>' +
                        '<td id="recieveDetailId">' + obj.id + '</td>' +
                        '<td id="sku">' + obj.sku + '</td>' +
                        '<td>' + obj.sku_name + '</td>' +
                        '<td>' + obj.transfer_hopper_id + '</td>' +
                        '<td>' + obj.remark + '</td>' +
                        '<td>' + obj.check_man + '</td>' +
                        '<td>' + obj.att_time + '</td>' +
                        '<td>' + obj.logisShow + '</td>' +
                        '<td>' + obj.arrival_quantity + '</td>' +
                        '<td>' + button + '</td>';
                $("#txtHint").html(strTem); //结果展示到id为txtHint的标签中

            },

            error: function () {
                layer.msg('查询失败,请检查输入,无法解决请找IT',{'icon':'5'});
            }
        });

    }

    /**
     * 物流属性确认
     */
    function checkSkuLogistic() {
        var recieveDetailId = $('#recieveDetailId').text();
        var skuLogistic = $('#slt_logistic option:selected').val();
        var poId = $('#poId').text();
        var sku = $('#sku').text();

        if ('' == skuLogistic) {
            layer.msg('请选择属性!',{'icon':'5'});
            return;
        }

        $.ajax({
            url: '__URL__/check_attr',
            data: {'recieveDetailId':recieveDetailId,'skuLogistic':skuLogistic,'poId':poId,'sku':sku},
            type: 'get',
            dataType: 'json',
            async: true,

            beforeSend:function(){
                //请求前的处理
                $('#check').text('正在审核...');
                $('#check').attr('disabled','true');
            },

            success: function (data) {
                layer.msg('审核成功',{'icon':'6'});
                getInfo();
            },

            error: function () {
                layer.msg('审核失败,请重试,无法解决请找IT',{'icon':'5'});
                getInfo();
            }
        })
    }

    /**
     * 去掉字符串左右两侧的空格
     * @param str
     * @returns {void|string|XML}
     */
    function trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
</script>